package com.cn.customer.housekeeping.housekeepingc.ui;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;

import com.cn.customer.housekeeping.housekeepingc.R;
import com.cn.customer.housekeeping.housekeepingc.bean.BaseResp;
import com.cn.customer.housekeeping.housekeepingc.bean.ServicekindListResp;
import com.cn.customer.housekeeping.housekeepingc.biz.personcenter.IUserLoginView;
import com.cn.customer.housekeeping.housekeepingc.biz.personcenter.InterfacePresenter;
import com.cn.customer.housekeeping.housekeepingc.constant.Constants;
import com.cn.customer.housekeeping.housekeepingc.constant.URLUtil;
import com.cn.customer.housekeeping.housekeepingc.ui.adapter.CNKFixedPagerAdapter;
import com.cn.customer.housekeeping.housekeepingc.ui.base.BaseFragmentActivity;
import com.cn.customer.housekeeping.housekeepingc.ui.fragment.ShopOrderListFragment;
import com.cn.customer.housekeeping.housekeepingc.util.ToastUtil;

import java.util.ArrayList;
import java.util.List;

/***
 * 商铺
 */
public class ShopOrderListActivity extends BaseFragmentActivity implements IUserLoginView {
    private InterfacePresenter mInterfacePresenter;
    private TabLayout tab_layout;
    private ViewPager info_viewpager;
    private List<Fragment> fragments;
    private CNKFixedPagerAdapter mPagerAdater;
    private String type, cityname, title;
    private List<ServicekindListResp> titles = new ArrayList<ServicekindListResp>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_shoporder_list);
        super.onCreate(savedInstanceState);


    }


    @Override
    public void initViews() {
        mInterfacePresenter = new InterfacePresenter();
        mInterfacePresenter.attachView(ShopOrderListActivity.this);
        tab_layout = (TabLayout) findViewById(R.id.tab_layout);
        info_viewpager = (ViewPager) findViewById(R.id.info_viewpager);
    }

    @Override
    public void initListeners() {

    }


    @Override
    public void initData() {
        type = getIntent().getExtras().getString(Constants.type);
        cityname = getIntent().getExtras().getString(Constants.cityname);
        title = getIntent().getExtras().getString(Constants.title);
        tvTopTitle.setText(title);
        ToastUtil.makeText(ShopOrderListActivity.this, type);
        ServicekindListResp m = new ServicekindListResp();
        m.setName("全部项目");
        m.setImgurl("drawable://" + R.mipmap.icon_quanbu_default);
        m.setSubtype(1);

        ServicekindListResp m2 = new ServicekindListResp();
        m2.setName("推荐技师");
        m2.setImgurl("drawable://" + R.mipmap.icon_tuijianjishi_default);
        m2.setSubtype(2);
        ServicekindListResp m3 = new ServicekindListResp();
        m3.setName("促销项目");
        m3.setImgurl("drawable://" + R.mipmap.icon_cuxiao_default);
        m3.setSubtype(3);
        ServicekindListResp m4 = new ServicekindListResp();
        m4.setName("用户评价");
        m4.setImgurl("drawable://" + R.mipmap.icon_pingjia_default);
        m4.setSubtype(4);
        titles.add(m);
        titles.add(m2);
        titles.add(m3);
        titles.add(m4);


        fragments = new ArrayList<>();
        for (int i = 0; i < titles.size(); i++) {

            String subtype = titles.get(i).getSubtype() + "";
            ShopOrderListFragment oneFragment = new ShopOrderListFragment().newInstance(type, subtype, cityname);
            fragments.add(oneFragment);
        }
        mPagerAdater = new CNKFixedPagerAdapter(getSupportFragmentManager());
        mPagerAdater.setTitles(titles);
        mPagerAdater.setFragments(fragments);
        info_viewpager.setAdapter(mPagerAdater);
        tab_layout.setupWithViewPager(info_viewpager);
        tab_layout.setTabMode(TabLayout.MODE_FIXED);
        for (int i = 0; i < titles.size(); i++) {
            TabLayout.Tab tab = tab_layout.getTabAt(i);
            tab.setCustomView(mPagerAdater.getTabView(i));
        }

        mInterfacePresenter.getSubServiceKind(type, cityname);

    }

    @Override
    public void onError(BaseResp s) {

    }


    @Override
    public void onSuccess(BaseResp s) {
        if (s.getUrl().equals(URLUtil.url_get_getSubServiceKind)) {//请求服务子类型

        }


    }

    @Override
    public void setHeader() {
        super.setHeader();
        rlTitle.setVisibility(View.VISIBLE);
        tvTopTitle.setText("");
    }


}
